package com.dd.edu.guava.conctroller;

import com.dd.edu.guava.entity.HotBean;
import com.dd.edu.guava.service.HotBeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.concurrent.ExecutionException;

/**
 * 客户端访问数据，经过service，
 * 先从本地缓存guava读取，
 * 无数据，则从分布式缓存redis读取，
 * 还没有，则从数据库读取数据
 *
 */
@Controller
public class HotBeanController {

    @Autowired
    private HotBeanService hotBeanService;


    @RequestMapping(path = "/hot/{id}")
    @ResponseBody
    public HotBean getHotById(@PathVariable("id") Integer id) throws ExecutionException {
        return hotBeanService.getHotBeanById(id);
    }

}
